package com.ltmall.api.manager.impl;

import com.ltmall.api.bean.*;
import com.ltmall.api.dao.impl.AccountDAO;
import com.ltmall.api.manager.AccountManager;
import com.ltmall.api.util.PageUtil;

import java.util.List;

public class AccountManagerImpl implements AccountManager {

    private AccountDAO aDAO;

    public AccountDAO getaDAO() {
        return aDAO;
    }

    public void setaDAO(AccountDAO aDAO) {
        this.aDAO = aDAO;
    }

    @Override
    public boolean addClientAccount(ClientAccount account) {
        return aDAO.persist(account);
    }

    @Override
    public boolean updateClientAccount(ClientAccount account) {
        return aDAO.update(account);
    }

    @Override
    public boolean isPhoneUsed(String phone) {
        return aDAO.isPhoneUsed(phone);
    }

    @Override
    public int isHaveAccount(String openid) {
        return aDAO.isHaveAccount(openid);
    }

    @Override
    public void initConfigAndInfo(ClientConfig config, ClientInfo info) {
        aDAO.addClientConfig(config);
        aDAO.addClientInfo(info);
    }

    @Override
    public boolean phoneLogin(String phone, String pass) {
        return aDAO.phoneLogin(phone, pass);
    }

    @Override
    public ClientConfig getConfig(int userID) {
        return aDAO.getConfig(userID);
    }

    @Override
    public ClientAccount getAccount(String phone, int userID) {
        return aDAO.getAccount(phone, userID);
    }

    @Override
    public boolean updateToken(int userID, String token) {
        return aDAO.updateToken(userID, token);
    }

    @Override
    public boolean updateInfo(int userID, String name, int sex) {
        return aDAO.updateInfo(userID, name, sex);
    }

    @Override
    public boolean updateLevel(int userId, int levelId) {
        return aDAO.updateLevel(userId, levelId);
    }

    @Override
    public boolean validate(int userID, String userToken) {
        return aDAO.validate(userID, userToken);
    }

    @Override
    public ClientInfo getInfo(int userID) {
        return aDAO.getInfo(userID);
    }

    @Override
    public boolean updatePhoto(int userID, String photo) {
        return aDAO.updatePhoto(userID, photo);
    }

    @Override
    public boolean addDelevery(DeliveryAddr addr) {
        return aDAO.addDelevery(addr);
    }

    @Override
    public boolean updateDelevery(int addrID, int userID, String name, String phone,
                                  String address, String province, String city, String county,
                                  int isDefault) {
        boolean opTag = aDAO.updateDelevery(addrID, userID, name, phone, address, province, city,
                county, isDefault);
        // 表示为缺省的
        if (isDefault == 1) {
            // 设置别的不默认
            aDAO.updateOtherDelevery(userID, addrID, 0);
        }
        return opTag;
    }

    @Override
    public boolean deleDelivery(int addrID) {
        return aDAO.deleDelivery(addrID);
    }

    @Override
    public List<DeliveryAddr> getDelivery(int userID, int number) {
        return aDAO.getDelivery(userID, number);
    }

    @Override
    public boolean updatePass(int userID, String pass) {
        return aDAO.updatePass(userID, pass);
    }

    @Override
    public boolean addBussinessInfo(BussinessInfo bInfo) {
        return aDAO.addBussinessInfo(bInfo);
    }

    @Override
    public void addBussinessAccount(BussinessAccount bAccount) {
        aDAO.addBussinessAccount(bAccount);
    }

    @Override
    public DeliveryAddr getAddr(int addrID) {
        return aDAO.getAddr(addrID);
    }

    @Override
    public boolean collection(Collection collection) {
        boolean extTag = aDAO.isCollectionExist(collection);
        if (!extTag) {
            return aDAO.addCollection(collection);
        } else {
            return aDAO.cancelCollection(collection.getGoodsID(), collection.getUserID());
        }
    }

    @Override
    public List<?> collectionList(int userID, PageUtil page) {
        return aDAO.collectionList(userID, page);
    }

    @Override
    public boolean editHome(int userID, String province, String city, String county) {
        return aDAO.editHome(userID, province, city, county);
    }

    @Override
    public boolean editDirectSupplyId(int userID, String directSupplyId) {
        return aDAO.editDirectSupplyId(userID, directSupplyId);
    }

    public boolean cancelCollection(int collectionID, int userID) {
        return aDAO.cancelCollection(collectionID, userID);
    }

    @Override
    public boolean addFeedback(Feedback feedback) {
        return aDAO.addFeedback(feedback);
    }

    @Override
    public ThClientPlatforms checkUserExistByOpenID(String opendID) {
        return aDAO.checkUserExistByOpenID(opendID);
    }

    @Override
    public void addClientPlatform(ThClientPlatforms platform) {
        aDAO.addClientPlatform(platform);
    }

    @Override
    public ThClientPlatforms getClientPlatformByUserId(int userId) {
        return aDAO.getClientPlatformByUserId(userId);
    }

    @Override
    public ThClientPlatforms getClientPlatformByOpenId(String openId) {
        return aDAO.getClientPlatformByOpenId(openId);
    }

    @Override
    public ThUserLevels userLevelGet(int levelId) {
        return aDAO.userLevelGet(levelId);
    }

}
